import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    baseUrl: "https://shslqxh.1meeting.com/coach/admin", // 默认前端地址
    baseAPIUrl: "https://shslqxh.1meeting.com/coach/api", // 默认后端地址
    // 基本信息
    loginToken:
      JSON.parse(JSON.stringify(localStorage.getItem("ADMIN_LOGINTOKEN"))) ||
      "", // 登录验证token
    loginUserId:
      JSON.parse(JSON.stringify(localStorage.getItem("ADMIN_LOGINUSERID"))) ||
      "", // 登录用户id
    loginType:
      JSON.parse(localStorage.getItem("ADMIN_LOGINTYPE")) ||
      "", // 登录用户类型
    loginUserName:
      JSON.parse(localStorage.getItem("ADMIN_LOGINUSERNAME")) || "", // 登录用户名


    // 页面缓存
  },
  mutations: {
    // 更新token
    set_loginToken (state, value) {
      state.loginToken = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINTOKEN", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINTOKEN");
      }
    },
    // 存储用户类型
    set_loginType (state, value) {
      state.loginType = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINTYPE", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINTYPE");
      }
    },
    // 更新登录id
    set_loginUserId (state, value) {
      state.loginUserId = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINUSERID", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINUSERID");
      }
    },
    // 更新登录用户名
    set_loginUserName (state, value) {
      state.loginUserName = value;
      if (value != "") {
        localStorage.setItem("ADMIN_LOGINUSERNAME", JSON.stringify(value));
      } else {
        localStorage.removeItem("ADMIN_LOGINUSERNAME");
      }
    },
  },
  actions: {},
  modules: {},
});
